package server

import (
	"github.com/labstack/echo/v4/middleware"
	"golang.org/x/time/rate"
	"techoiceness.com/aiagent/llm-gateway/internal/server/handlers"
	customMiddleware "techoiceness.com/aiagent/llm-gateway/internal/server/middleware"
)

func (s *Server) setupRoutes() {
	// 全局中间件 - server层只关心这些
	s.e.Use(middleware.Recover())
	s.e.Use(middleware.CORS())
	s.e.Use(middleware.RequestID()) // 添加请求ID支持

	// 使用自定义的HTTP logger替代默认logger
	s.e.Use(customMiddleware.HTTPLogger())

	s.e.Use(middleware.RateLimiter(middleware.NewRateLimiterMemoryStore(rate.Limit(100))))

	// 创建handlers管理器，它会自己管理所有依赖
	handlerManager, err := handlers.NewRootHandler(s.cfg, s.db)
	if err != nil {
		panic(err)
	}

	// 让handlers管理器注册所有路由
	handlerManager.RegisterRoutes(s.e)
}
